import { defineStore } from "pinia";
import { getList } from "@/api/user.js";
const useInstructionStore = defineStore("instruction", {
  state: () => ({
    list: []
  }),
  actions: {
    setData(list) {
      this.list = list;
    },
    getData() {
      getList().then(res => {
        this.setData(res.data);
      });
    },
    addField(index, field, value) {
      this.list[index][field] = value; // 添加字段
      this.list[index].timestamp = Date.now(); // 更新时间戳
      this.list[index].isRead = false; // 设置未读
      console.log(this.list);
    },
    setRead(index) {
      this.list[index].isRead = true; // 设置已读
    }
  }
});

export default useInstructionStore;
